<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="apple-mobile-web-app-capable" content="yes" />
        <meta name="apple-mobile-web-app-status-bar-style" content="black" />
        <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1.0, maximum-scale=1.0, minimal-ui" />
        
        <title>Query String Documentation</title>
        
        <script src="/js/greyspots.js" type="text/javascript"></script>
        <link href="/css/greyspots.css" type="text/css" rel="stylesheet" />
        
        <script src="/js/ace/ace.js" data-ace-base="/js/ace/" type="text/javascript" charset="utf-8"></script>
        <script src="/js/ace/ext-language_tools.js" type="text/javascript"></script>
        <script src="/js/ace/ext-searchbox.js" type="text/javascript"></script>
        
        <script src="doc-library/doc.js" type="text/javascript"></script>
        <link href="doc-library/doc.css" type="text/css" rel="stylesheet" />
    </head>
    <body>
        <gs-jumbo>
            <h1 class="text-center">Query String</h1>
        </gs-jumbo>
            
        <gs-container min-width="sml;med;lrg">
            <h3>Functions:</h3>
            <pre><code>GS.getQueryString()
GS.qryToJSON(&lt;QUERYSTRING-TO-CONVERT&gt;)
GS.qryFromJSON(&lt;JSON-TO-CONVERT&gt;)
GS.qryToWhere(&lt;QUERYSTRING&gt;[, &lt;COLUMN-IN-QUERYSTRING&gt;[, &lt;COLUMN-IN-TARGET&gt;]])
GS.qryGetKeys(&lt;QUERYSTRING&gt;)
GS.qryGetVals(&lt;QUERYSTRING&gt;)
GS.qryDeleteKey(&lt;QUERYSTRING&gt;, &lt;COLUMN-TO-DELETE&gt;)
GS.qryGetVal(&lt;QUERYSTRING&gt;, &lt;COLUMN-TO-GET&gt;)
GS.qrySetVal(&lt;QUERYSTRING&gt;, &lt;COLUMN=NEWVALUE&gt;);</code></pre>
            
            <h3>Description:</h3>
            <p>
                A querystring is a data structure in the format of: "COLUMN=VALUE&COLUMN2=VALUE2". Notice that there are column/value pairs and the pairs are seperated by ampersands. Columns may also be called keys for shortness.<br /><br />
                
                These functions are used for reading, converting, generating and altering querystrings. See also: <a href="doc-jslib-safe-uri-decode.html">Safe URI Decoding</a> and <a href="doc-jslib-url-state.html">URL State Functions</a>.
            </p>
            
            <b class="doc-header">Examples:</b>
            <div class="doc-example-description">
                <span class="h3">GS.getQueryString Example:</span><br />
                <p>This function returns the querystring from the window.</p>
            </div>
            <gs-doc-example query-string="test=testvalue">
                <template for="html" height="5">
                    <gs-button onclick="testGetQueryString()">Get Query String</gs-button>
                    <div id="result"></div>
                </template>
                <template for="js" height="7">
                    function testGetQueryString() {
                        document.getElementById('result').textContent = GS.getQueryString();
                    }
                </template>
            </gs-doc-example>
            
            
            <div class="doc-example-description">
                <span class="h3">GS.qryToJSON Example:</span><br />
                <p>This function converts a querystring to a JSON object.</p>
            </div>
            <gs-doc-example>
                <template for="html" height="5">
                    <gs-button onclick="testQryToJSON()">Convert To JSON</gs-button>
                    <div id="result"></div>
                </template>
                <template for="js" height="9">
                    function testQryToJSON() {
                        var data = GS.qryToJSON('column1=value1&column2=value2');
                        
                        document.getElementById('result').textContent = data.column1 + ' ' + data.column2;
                    }
                </template>
            </gs-doc-example>
            
            
            <div class="doc-example-description">
                <span class="h3">GS.qryFromJSON Example:</span><br />
                <p>This function turns a JSON object into a querystring.</p>
            </div>
            <gs-doc-example>
                <template for="html" height="5">
                    <gs-button onclick="testQryFromJSON()">Convert To Query String</gs-button>
                    <div id="result"></div>
                </template>
                <template for="js" height="9">
                    function testQryFromJSON() {
                        var data = {'column1': 'value1', 'column2': 'value2'};
                        
                        document.getElementById('result').textContent = GS.qryFromJSON(data);
                    }
                </template>
            </gs-doc-example>
            
            
            <div class="doc-example-description">
                <span class="h3">GS.qryToWhere Example:</span><br />
                <p>This function converts a querystring to a Postgres WHERE clause</p>
            </div>
            <gs-doc-example>
                <template for="html" height="8">
                    <gs-text id="column-to-use" value="column1"></gs-text>
                    <gs-text id="column-name-in-where" value="id"></gs-text>
                    <gs-button onclick="testQryToWhere()">Generate WHERE</gs-button>
                    <div id="result"></div>
                </template>
                <template for="js" height="13">
                    function testQryToWhere() {
                        var queryString = 'column1=value1&column2=value2';
                        
                        document.getElementById('result').textContent =
                            GS.qryToWhere(queryString,
                                document.getElementById('column-to-use').value,
                                document.getElementById('column-name-in-where').value);
                    }
                </template>
            </gs-doc-example>
            
            
            <div class="doc-example-description">
                <span class="h3">GS.qryGetKeys Example:</span><br />
                <p>This function returns an array of all the columns in a querystring.</p>
            </div>
            <gs-doc-example>
                <template for="html" height="4">
                    <gs-button onclick="testQryGetKeys()">Get Keys</gs-button>
                    <div id="result"></div>
                </template>
                <template for="js" height="10">
                    function testQryGetKeys() {
                        var queryString = 'column1=value1&column2=value2';
                        
                        document.getElementById('result').textContent =
                            JSON.stringify(GS.qryGetKeys(queryString));
                    }
                </template>
            </gs-doc-example>
            
            
            <div class="doc-example-description">
                <span class="h3">GS.qryGetVals Example:</span><br />
                <p>This function returns an array of all the values in a querystring.</p>
            </div>
            <gs-doc-example>
                <template for="html" height="4">
                    <gs-button onclick="testQryGetValues()">Get Values</gs-button>
                    <div id="result"></div>
                </template>
                <template for="js" height="10">
                    function testQryGetValues() {
                        var queryString = 'column1=value1&column2=value2';
                        
                        document.getElementById('result').textContent =
                            JSON.stringify(GS.qryGetVals(queryString));
                    }
                </template>
            </gs-doc-example>
            
            
            <div class="doc-example-description">
                <span class="h3">GS.qryDeleteKey Example:</span><br />
                <p>This function removes a column/value pair from a querystring.</p>
            </div>
            <gs-doc-example>
                <template for="html" height="4">
                    <gs-button onclick="testQryDeleteKey()">Drop Column</gs-button>
                    <div id="result"></div>
                </template>
                <template for="js" height="12">
                    function testQryDeleteKey() {
                        var queryString = 'column1=value1&column2=value2';
                        
                        queryString = GS.qryDeleteKey(queryString, 'column1');
                        
                        document.getElementById('result').textContent = queryString;
                    }
                </template>
            </gs-doc-example>
            
            
            <div class="doc-example-description">
                <span class="h3">GS.qryGetVal Example:</span><br />
                <p>This function gets a value from a querystring based on a column.</p>
            </div>
            <gs-doc-example>
                <template for="html" height="4">
                    <gs-button onclick="testQryGetVal()">Get Value</gs-button>
                    <div id="result"></div>
                </template>
                <template for="js" height="10">
                    function testQryGetVal() {
                        var queryString = 'column1=value1&column2=value2';
                        
                        document.getElementById('result').textContent =
                            GS.qryGetVal(queryString, 'column1');
                    }
                </template>
            </gs-doc-example>
            
            
            <div class="doc-example-description">
                <span class="h3">GS.qrySetVal Example:</span><br />
                <p>This function sets a value in a querystring.</p>
            </div>
            <gs-doc-example>
                <template for="html" height="4">
                    <gs-button onclick="testQrySetVal()">Get Value</gs-button>
                    <div id="result"></div>
                </template>
                <template for="js" height="14">
                    function testQrySetVal() {
                        var queryString = 'column1=value1&column2=value2';
                        
                        queryString = GS.qrySetVal(queryString, 'column2=newvalue2');
                        
                        document.getElementById('result').textContent = queryString;
                    }
                </template>
            </gs-doc-example>
        </gs-container>
    </body>
</html>